<?php
namespace expand;

date_default_timezone_set('PRC');
//require_once(__DIR__. '/yst/SOAClient.php');
//require_once(__DIR__. '/yst/RSAUtil.php');
require_once(__DIR__. '/yun/YunBase.php');
Class YunPay{

	private $client;
	private $privateKey;
	private $publicKey;
	private $webUrl;
	private $accountSetNo;

	public function __construct()
    {	
		//$serverAddress = "http://116.228.64.55:9092/service/gateway/frontTrans.do?"; //测试环境
//		$serverAddress = "https://yun.allinpay.com/yungateway/frontTrans.do?"; //正式环境
//		$serverAddress = 'http://116.228.64.55:6900/yungateway/frontTrans.do?'; // 2.0测试
		$serverAddress = 'https://fintech.allinpay.com/yungateway/frontTrans.do?'; // 2.0正式

		$sysid = "100009000406";
		$alias = "100009000406";
		$privatePath = ROOT_PATH."public/static/hry/100009000406_private.pem";
		$publicPath = ROOT_PATH."public/static/hry/100009000406_public.pem";
		$pwd = "942961";
		$signMethod = "SHA1WithRSA";
		
		$this->webUrl = input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME').'/';
//		$this->client = new SOAClient();
		$this->client = new YunBase(); // 2.0修改
		$this->accountSetNo = "200232";
//		$this->accountSetNo='200126'; //2.0修改
//		$this->privateKey = RSAUtil::loadPrivateKey($alias, $privatePath, $pwd);
//		$this->publicKey = RSAUtil::loadPublicKey($alias, $publicPath, $pwd);
		$this->client->setServerAddress($serverAddress);
		$this->client->setSignKey();
//		$this->client->setPublicKey($this->publicKey);
		$this->client->setSysId($sysid);
//		$this->client->setSignMethod($signMethod);
	}

	//快捷-确认支付
	public function surePay($bizUserId,$order) {
		$param["bizUserId"] = $bizUserId;
		$param["bizOrderNo"] = $order;
		$param["consumerIp"] = $_SERVER["REMOTE_ADDR"];

		$result = $this->client->getUrl("OrderService", "pay", $param);
		return $result;
	}


	//2.0加密
	public function rsaEncrypt($str, $publicKey, $privateKey) {
		$rsaUtil = new YunBase();
		$encryptStr = $rsaUtil->strEncryptWithRsa($str);
		return $encryptStr;
	}

	//2.0解密
	public function rsaDecrypt($str, $publicKey, $privateKey) {
		$rsaUtil = new YunBase();
		$encryptStr = $rsaUtil->strDecryptWithRsa($str);
		return $encryptStr;
	}

//	//加密
//	public function rsaEncrypt($str, $publicKey, $privateKey) {
//		$rsaUtil = new RSAUtil($publicKey, $privateKey);
//		$encryptStr = $rsaUtil->encrypt($str);
//		return $encryptStr;
//	}
//
//	//解密
//	public function rsaDecrypt($str, $publicKey, $privateKey) {
//		$rsaUtil = new RSAUtil($publicKey, $privateKey);
//		$encryptStr = $rsaUtil->decrypt($str);
//		return $encryptStr;
//	}
}
?>